import os

# 如果是posix，说明系统是Linux、Unix或Mac OS X，如果是nt，就是Windows系统
print(os.name)
print(os.uname())
# 查看当前目录的绝对路径:
print(os.path.abspath('.'))
print(os.environ)
# environ({'PATH': '/Users/liangbo/PycharmProjects/untitled/venv/bin:/Users/liangbo/opt/anaconda3/bin:/Users/liangbo/opt/anaconda3/condabin:
# /Users/liangbo/bin:/Users/liangbo/Library/Android/android-ndk-r12b:/usr/local/mysql-8.0.18-macos10.14-x86_64/bin:
# /Users/Android_soft/gradle/bin:/usr/local/bin:/Users/liangbo/Documents/dartSDK/dartsdk/bin:/Users/liangbo/Documents/FlutterSdk/flutter/bin:/usr/bin:
# /bin:/usr/sbin:/sbin:/Users/liangbo/Library/Android/sdk/platform-tools:/Users/liangbo/Library/Android/sdk/toolus',
# 'CONDA_DEFAULT_ENV': 'base', 'CONDA_EXE': '/Users/liangbo/opt/anaconda3/bin/conda', 'CONDA_PYTHON_EXE':

print('*' * 30)
print(os.path)
print('*' * 70)
print(os.pardir)
print('*' * 110)

print('*' * 30)
path = os.path.dirname(__file__)
print(path)

print(type(path))  # <class 'str'>

result = os.path.join(path, 'a1.jpg')
print(result)  # /Users/liangbo/PycharmProjects/untitled/chapter03/a1.jpg

print('*' * 30)
path = '/Users/liangbo/PycharmProjects/untitled/chapter03/TestOs001.py'

# 要拆分路径时
result = os.path.split(path)
print(result)

print(result[1])

# 要拆分路径时
result = os.path.splitext(path)  # ('/Users/liangbo/PycharmProjects/untitled/chapter03/TestOs001', '.py')
print(result)

size = os.path.getsize(path)
print(size)

print('#' * 40)
""" Return a unicode string representing the current working directory. """
print(os.getcwd())

#  切换目录
os.listdir(r'/Users/liangbo')

path = r'/Users/liangbo'
filelist = os.listdir(path)
print(filelist)

var = [x for x in os.listdir('.') if os.path.isfile(x) and os.path.splitext(x)[1] == '.py']

print('()' * 90)

print(type(var))
print(var)
print('()' * 50)
print(list(var))
print('()' * 90)


# os.remove(fileaaa)
# os.rmdir(filedoc)
# os.mkdir() 创建文件夹

# 复制 文件
def copy(src, target):
    if (os.path.isdir(src) and os.path.isdir(target)):
        filelist = os.listdir(src)

        for file in filelist:
            path = os.path.join(src, file)
            with open(path, 'rb') as rstream:
                container = rstream.read()

                path1 = os.path.join(target, file)
                with open(path1, 'wb') as wstream:
                    wstream.write(container)
    else:
        print('Copy Success!')


print("%%()" * 50)
print(os.environ.get('key'))
print(os.environ.get('PATH'))
